package com.bigdata.security.shiro.filter;/**
 * Created by Administrator on 2019/7/9 0009.
 */

import com.bigdata.model.User;
import com.bigdata.utils.shiro.ShiroUtils;
import org.apache.shiro.cache.CacheManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * @author Administrator
 * @description
 * @date 2019/7/9 0009
 */
public class LogoutFilter extends org.apache.shiro.web.filter.authc.LogoutFilter {

    private static final Logger log = LoggerFactory.getLogger("LogoutFilter");
    private String loginUrl;

    public String getLoginUrl() {
        return loginUrl;
    }

    public void setLoginUrl(String loginUrl) {
        this.loginUrl = loginUrl;
    }

    @Override
    protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception {

        try {
            org.apache.shiro.subject.Subject subject = getSubject(request, response);
            String redireUrl = getRedirectUrl(request, response, subject);
            try {
                subject.logout();
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return false;
    }

    public void setCacheManager(CacheManager cacheManager) {

    }
}
